package com.hhl.lamda.convertarray2stream;

import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author HHL
 * @description
 * @date 2018/11/19 - 9:18
 */
public class ConvertArray2Stream {

    public static void main(String[] args) {

        String[] array = {"a", "b", "c", "d", "e"};

        //Arrays.stream
        Stream<String> stream1 = Arrays.stream(array);
        stream1.forEach(x -> System.out.print(x));
        System.out.println();


        //Stream.of
        Stream<String> stream2 = Stream.of(array);
        stream2.forEach(x -> System.out.print(x));
        System.out.println();



//        2. Primitive Arrays  原始数组
//        For primitive array, the Arrays.stream and Stream.of will return different output.
        int[] intArray = {1, 2, 3, 4, 5};

        // 1. Arrays.stream -> IntStream
        IntStream intStream1 = Arrays.stream(intArray);
        intStream1.forEach(x -> System.out.print(x));
        System.out.println();


        // 2. Stream.of -> Stream<int[]>
        Stream<int[]> temp = Stream.of(intArray);


        // 2. Stream.of -> Stream<int[]>
        Stream<int[]> temp1 = Stream.of(intArray);



        // Cant print Stream<int[]> directly, convert / flat it to IntStream
        IntStream intStream2 = temp1.flatMapToInt(x -> Arrays.stream(x));
        intStream2.forEach(x -> System.out.print(x));
        System.out.println();














    }
}
